<template>
  <div>
    <div class="leave-list">
      <router-link v-for="(item, index) in list" :key="index" :to="`/leaveDetail/${item.id}`">
        <div class="leave-item">
          <div class="avatar-box">
            <div class="avatar"><img :src="item.head_sculpture ? item.headimgurl : avatar" alt="" width="100%"></div>
            <div class="dot" v-if="item.status === 3"></div>
          </div>
          <div class="user">
            <div class="nickname">
              <p class="name">{{ item.name }}</p>
              <p class="course">{{ item.kcname }}</p>
            </div>
            <div class="status">{{ item.status === 1 ? '允许' : (item.status === 2 ? '不允许' : '未审批') }}</div>
          </div>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script>
import api from '@/api'
export default {
  name: 'leave-list',
  data () {
    return {
      avatar: require('@/assets/img/icon-avatar.png'),
      list: []
    }
  },
  methods: {
    getLeaveList () {
      let params = {teacher_id: JSON.parse(sessionStorage.getItem('user')).id}
      api.teacherLeaveList({
        params,
        callback: res => {
          if (res.data.error_code === 0) {
            let arr1 = []
            let arr2 = []
            res.data.data.forEach(item => {
              if (item.status === 3) {
                arr1.push(item)
              } else {
                arr2.push(item)
              }
            })
            this.list = [...arr1, ...arr2]
          }
        }
      })
    }
  },
  created () {
    this.getLeaveList()
  }
}
</script>

<style scoped>
  .leave-item{
    display: flex;
    padding: 0 0 0 15px;
    align-items: center;
  }
  .leave-item .avatar-box{
    flex-shrink: 0;
    flex-grow: 0;
    position: relative;
    margin-right: 20px;
  }
  .leave-item .avatar{
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
  }
  .leave-item .user{
    flex-shrink: 1;
    flex-grow: 1;
    border-bottom: 1px solid #999;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }
  .user .nickname .name{
    font-size:18px;
    font-family:PingFang SC;
    font-weight:bold;
    line-height:30px;
    color:rgba(26,29,32,1);
  }
  .user .nickname .course{
    font-size: 11px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 16px;
    color: rgba(102,102,102,1);
    letter-spacing: 2px;
  }
  .user .status{
    font-size:14px;
    font-family:PingFang SC;
    font-weight:bold;
    line-height:20px;
    color:rgba(102,102,102,1);
  }
</style>
